package tcp.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

/**
 * 模拟访问redis zookeeper等
 * @author Han
 */
public class TelnetTest {
	public static void main(String[] args) throws IOException {
		Socket socket = new Socket("192.168.1.159", 6379);
		OutputStream socketOut = socket.getOutputStream();
		//redis的管道
		String echo="set a 1\r\n";
		System.out.println("发送命令:"+echo);
		socketOut.write(echo.getBytes());
		InputStream is = socket.getInputStream();
		//socket.shutdownOutput();
		BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
		String line = null;
		while((line = br.readLine()) != null){
			System.out.println(line);
		}
		br.close();
		is.close();
		socket.close();
		System.out.println("呵呵");
	}
}
